package com.xuchaotong.utils;

import java.lang.reflect.Field;
import java.util.ArrayDeque;

public class Demo {
    public static void main(String[] args) {
//        String[] s = new String[10];
//        System.out.println(s.length);

        Demo d = new Demo();
//        d.adeque2();

//        d.adeque1();

//        d.sysArraycopy(12,0,4);
//        d.sysArraycopy(0,4,12);

        d.shortMethod();

    }

    public void adeque1() {
        ArrayDeque ad = new ArrayDeque(3);
        ad.addFirst(1);
        ad.addFirst(2);
        ad.addFirst(3);
        ad.addFirst(4);
        ad.addFirst(5);
        ad.addFirst(6);
        ad.addLast(7);
        ad.addLast(8);
        ad.addLast(9);

        try {
//            Field field = ArrayDeque.class.getDeclaredField("head");
//            Field field = ad.getClass().getDeclaredField("head");
//            field.setAccessible(true);
//            Integer head = (Integer) field.get(ad);
//            System.out.println(head);
//
//            Field field1 = ad.getClass().getDeclaredField("tail");
//            field1.setAccessible(true);
//            Integer tail = (Integer) field1.get(ad);
//            System.out.println(tail);

            Field field3 = ad.getClass().getDeclaredField("elements");
            field3.setAccessible(true);
            Object[] elements = (Object[]) field3.get(ad);
//            System.out.println(elements.length);
            for (Object o : elements) {
                if (o == null) {
                    System.out.println("null");
                } else {
                    System.out.println(o.toString());
                }
            }
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public void adeque2() {
        ArrayDeque ad = new ArrayDeque();
        ad.addFirst(1);
        ad.addFirst(3);
        ad.addLast(2);

        for (int i = 0; i < ad.size(); i++) {
            System.out.println(ad.getFirst());
        }
    }

    public void sysArraycopy(int srcPos,int destPos,int len){
        for(int i = destPos;i < destPos + len;i++){
            System.out.println("Old: " + i + ",New: " + srcPos);
            srcPos++;
        }
    }

    public void shortMethod(){
        System.out.println("6" + 2);
    }
}
